import { homeBannerApi, homeBrandApi } from '@/api/home'

const state = {
  //品牌数据
  brandList: [],
//  轮播图数据
  bannerList:[]
}
const mutations = {
  setBrandList (state, payload) {
    state.brandList = payload
  },
  setBannerList(state,payload){
    state.bannerList = payload
  }
}
const actions = {
  async getBrandList ({ commit,state }) {
    if (!state.brandList.length) {
      const res = await homeBrandApi(10)
      commit('setBrandList', res.result)
      return res
    }
    return { result: state.brandList }
  },
  async getBannerList({commit,state}){
    if(!state.bannerList.length){
      const res = await  homeBannerApi()
      commit('setBannerList',res.result)
      return res.result
    }
    return state.bannerList
  }
}
const getters = {}
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
